﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.services.*;
    import net.wooga.pets.models.world.*;

    public class InitGameCommand extends Command {

		[Inject]
        public var tickModel:TickModel;
		[Inject]
        public var sessionModel:SessionModel;
		[Inject]
        public var userModel:UserModel;
		[Inject]
        public var environmentModel:EnvironmentModel;
		[Inject]
        public var gameStateModel:GameStateModel;
		[Inject]
        public var tutorialModel:TutorialModel;
		[Inject]
        public var keyboardInput:KeyboardInput;
		[Inject]
        public var socialNetworkService:ISocialNetworkService;
		[Inject]
        public var roomSlotsModel:RoomSlotsModel;
		[Inject]
        public var worldModel:WorldModel;
		[Inject]
        public var letterModel:LetterModel;

        override public function execute():void{
            this.tickModel.timestamp = this.sessionModel.timestamp;
            if (this.userModel.newUser){
                this.gameStateModel.state = GameStateModel.STATE_GAME_TUTORIAL;
            } else {
                this.gameStateModel.state = GameStateModel.STATE_GAME_RUNNING;
            };
            var _local1:int = (this.roomSlotsModel.availableRoomSlotsNumber - this.sessionModel.currentRooms.length);
            if ((((this.userModel.level == 2)) && ((_local1 == 1)))){
                this.tutorialModel.state = TutorialModel.ROOMTUTORIAL_CLICK_ON_SHOP;
            };
            this.sessionModel.hasFountain = !((Arrays.findByAttribute(this.sessionModel.currentRooms, ProtocolConstants.ROOM_TYPE, GameConstants.TYPE_FOUNTAIN) == null));
            this.tickModel.stage = contextView.stage;
            this.tickModel.start(GameConstants.LOOP_TIMER_FRAMERATE);
            this.keyboardInput.setStage(contextView.stage);
            var _local2:Boolean = this.environmentModel.liveVersion;
            this.keyboardInput.cheatingEnabled = !(_local2);
            this.letterModel.setLettersReadState(this.sessionModel.readLetters);
            if (this.sessionModel.currentRooms.length < 6){
                dispatch(new CreationEvent(CreationEvent.CREATE_CONSTRUCTION_SITES));
            };
            dispatch(new CreationEvent(CreationEvent.CREATE_MAIN_MENU));
            dispatch(new CreationEvent(CreationEvent.CREATE_META_MENU));
            dispatch(new InfoEvent(EventConstants.CREATE_COLLECTION_STATUS_DISPLAY));
            dispatch(new InfoEvent(EventConstants.INIT_WORLD, null, this.sessionModel.data));
        }

    }
}//package net.wooga.pets.controllers 
